package com.aaa.book_mall.dao.impl;

import com.aaa.book_mall.dao.ProlnDao;
import com.aaa.book_mall.entity.Detail;
import com.aaa.book_mall.entity.Proln;
import com.aaa.book_mall.util.JDBCUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * fileName:ProlnDaoImpl
 * description:
 * author:付亚星
 * createTime:2021/1/20 16:26
 * version:1.0.0
 */
public class ProlnDaoImpl implements ProlnDao {

    /**
     * 查询所有
     * @param proln
     * @return
     */
    @Override
    public List<Map<String, Object>> getAllProln(Proln proln) {
        String sql = "select * from ";
        return null;
    }

    /**
     * 新增
     * @param proln
     * @return
     */
    @Override
    public int insertProln(Proln proln) {
        String sql = "insert into t_proln values(null,?,?,?)";
        int update = JDBCUtil.update(sql, proln.getRuku_number(), proln.getBookid(), proln.getBookcount());
        return update;
    }

    /**
     * 根据number查询详情表
     * @param ruku_number
     * @return
     */
    @Override
    public List<Proln> queryProln(String ruku_number) {
        String sql = "select bookid,bookcount from t_proln where ruku_number=? ";
        List<List> lists = JDBCUtil.queryList(sql, ruku_number);
        ArrayList<Proln> prolns = new ArrayList<>();
        if(lists.size()>0){
            for (List list : lists) {
                Proln proln = new Proln((Integer)list.get(0),(Integer)list.get(1));
                prolns.add(proln);
            }
            return prolns;
        }
        return null;
    }

    /**
     * 查看对应订单详情时使用
     * @param ruku_number
     * @return
     */
    @Override
    public List<Map<String, Object>> showInfoProln(String ruku_number) {
        String sql = "SELECT td.ruku_number,tb.bookname,tb.price,td.bookcount,tb.count,tb.publisher from t_proln td inner JOIN t_book tb on tb.bookid=td.bookid where td.bookid in (select bookid from t_proln where ruku_number=?) and td.ruku_number=?";
        List<Map<String, Object>> maps = JDBCUtil.queryListMap(sql, ruku_number, ruku_number);
        return maps;
    }

}
